package jp.tuyano.helo.server;

import javax.jdo.PersistenceManager;

import jp.tuyano.core.PMF;
import jp.tuyano.helo.client.MyDataObject;
import jp.tuyano.helo.client.UpdatePDService;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class UpdatePDServiceImpl extends RemoteServiceServlet implements
        UpdatePDService {

    private static final long serialVersionUID = 1L;

    public MyDataObject getDataById(Long id) {
        PersistenceManager pm = PMF.get().getPersistenceManager();
        PersonalData data = (PersonalData) pm.getObjectById(PersonalData.class,
                id);
        return new MyDataObject(data.getId(), data.getName(),
                data.getMail(), data.getTel(), data.getMemo());
    }

    public String updateEntity(Long id, String name, String mail,
            String tel, String memo) {
        PersistenceManager pm = PMF.get().getPersistenceManager();
        PersonalData data = (PersonalData) pm.getObjectById(PersonalData.class,
                id);
        data.setName(name);
        data.setMail(mail);
        data.setTel(tel);
        data.setMemo(memo);
        pm.close();
        return "OK! updated!!";
    }
}
